// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database({
  env: 'gtss-2b1812'
})
exports.main = async(event, context) => {
  try {
    if (event.type == 'stu') {
      await db.collection('Student').doc(event.id).update({
        data: {
          stuName: event.name,
          stuSex: event.sex,
          stuPhone: event.phone,
          stuClass: event.stuClass
        }
      })
    }
    if (event.type == 'tea') {
      await db.collection('Teacher').doc(event.id).update({
        data: {
          teaName: event.name,
          teaSex: event.sex,
          teaPhone: event.phone,
          teaPost: event.teaPost
        }
      })
    }
    return {
      result: 1
    }
  } catch (e) {
    return {
      result: 0
    }
  }
}